# -*- mode: python ; coding: utf-8 -*-

import os
import sys

# 获取项目根目录（批处理会在仓库根执行），此处显式指向 excel_data_transformer-master
project_root = os.path.join(os.path.abspath(os.getcwd()), 'excel_data_transformer-master')
src_path = os.path.join(project_root, 'src')

# PyInstaller打包配置
block_cipher = None

# 分析主脚本
a = Analysis(
    [os.path.join(src_path, 'main.py')],
    pathex=[src_path],
    binaries=[],
    datas=[],  # 不打包 data，运行时从 exe 同级的 data 读取/写出
    hiddenimports=[
        'pandas',
        'numpy',
        'openpyxl',
        'tkinter',
        'tkinter.messagebox',
        'config.settings',
        'config.di_container',
        'services.data_processing_service',
        'interfaces.data_loader',
        'interfaces.form_metadata',
        'interfaces.transformers',
        'interfaces.excel_writer',
        'implementations.pandas_data_loader',
        'implementations.form_metadata_provider',
        # 业务适配器与合并模块
        'implementations.merge.base_subjects',
        'implementations.merge.cycle_processor',
        'implementations.merge.failure_list',
        'implementations.others.joiner',
        'implementations.pivot.pivot_metrics',
        'implementations.pivot.blood_draw',
        'implementations.pivot.lbup',
        # 通用构建器/加载器
        'common.pivot.period_pivot',
        'common.pivot.default_period_pivot',
        'common.pivot.custom_col_pivot',
        'common.loaders.model_loader',
        # 其他
        'implementations.excel_writer',
        'constants',
    ],
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    win_no_prefer_redirects=False,
    win_private_assemblies=False,
    cipher=block_cipher,
    noarchive=False,
)

pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)

exe = EXE(
    pyz,
    a.scripts,
    a.binaries,
    a.zipfiles,
    a.datas,
    [],
    name='Excel数据处理器',
    debug=False,
    bootloader_ignore_signals=False,
    strip=False,
    upx=True,
    upx_exclude=[],
    runtime_tmpdir=None,
    console=False,  # 设置为False以隐藏控制台窗口
    disable_windowed_traceback=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
    icon=None,  # 可以添加图标文件路径
)

# 确保data文件夹在打包后仍然可访问
coll = COLLECT(
    exe,
    a.binaries,
    a.zipfiles,
    a.datas,
    strip=False,
    upx=True,
    upx_exclude=[],
    name='Excel数据处理器'
)